package com.teira.rhrrealstate.session;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.jboss.seam.Component;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;

import com.teira.rhrrealstate.entity.TipoOperacion;

@Name("tipoOperacionConverter")
@BypassInterceptors
@org.jboss.seam.annotations.faces.Converter(forClass=TipoOperacion.class)
public class TipoOperacionConverter implements Converter {

	TipoOperacionHome tipoOperacionHome = (TipoOperacionHome) Component.getInstance(TipoOperacionHome.class);
	
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
		if(value == null)
			return null;
		
		return tipoOperacionHome.getEntityManager().find(TipoOperacion.class, value);
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
		return value != null && ((TipoOperacion)value).getId() != null ? ((TipoOperacion)value).getId() : "";
	}


}
